<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px">
      <el-form-item label="股票代码" prop="code">
        <el-input
          v-model="queryParams.code"
          clearable
          placeholder="请输入股票代码"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="股票名称" prop="name">
        <el-input
          v-model="queryParams.name"
          clearable
          placeholder="请输入股票名称"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="stockList">
      <el-table-column align="center" label="股票代码" prop="code" width="200"/>
      <el-table-column align="center" label="股票名称" prop="name" width="200"/>
      <el-table-column align="center" label="开盘价" prop="openPrice"/>
      <el-table-column align="center" label="昨日收盘价" prop="lastClosePrice"/>
      <el-table-column align="center" label="最高价" prop="maxPrice"/>
      <el-table-column align="center" label="最低价" prop="minPrice"/>
      <el-table-column align="center" label="最新价格" prop="latestPrice"/>
      <el-table-column align="center" label="总成交股数" prop="volume"/>
      <el-table-column align="center" label="总成交金额" prop="turnover"/>
      <el-table-column align="center" label="股票数量" prop="amount"/>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button
            icon="el-icon-view"
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
          >查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改人才股票对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="80vw">

      <el-descriptions :column="2" border class="margin-top" size="medium" title="发行人基本信息">
        <template slot="extra">
        </template>
        <el-descriptions-item>
          <template slot="label">
            姓名
          </template>
          <span>{{ issuer.name }}</span>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            性别
          </template>
          <span>{{ issuer.sex }}</span>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            年龄
          </template>
          <span>{{ issuer.age }}</span>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            学校
          </template>
          <span>{{ issuer.school }}</span>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            专业
          </template>
          <span>{{ issuer.major }}</span>
        </el-descriptions-item>
      </el-descriptions>

      <el-descriptions :column="2" border class="margin-top" title="股票信息">
        <el-descriptions-item label="股票代码">{{ form.code }}</el-descriptions-item>
        <el-descriptions-item label="股票名称">{{ form.name }}</el-descriptions-item>
        <el-descriptions-item label="开盘价（￥）">{{ form.openPrice }}</el-descriptions-item>
        <el-descriptions-item label="昨日收盘价（￥）">{{ form.lastClosePrice }}</el-descriptions-item>
        <el-descriptions-item label="最高价（￥）">{{ form.maxPrice }}</el-descriptions-item>
        <el-descriptions-item label="最低价（￥）">{{ form.minPrice }}</el-descriptions-item>
        <el-descriptions-item label="最新价格（￥）">
          <el-tag>{{ form.latestPrice }}</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="总成交股数">{{ form.volume }}</el-descriptions-item>
        <el-descriptions-item label="总成交金额（￥）">{{ form.turnover }}</el-descriptions-item>
        <el-descriptions-item label="股票数量">{{ form.amount }}</el-descriptions-item>
      </el-descriptions>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listOngoStock, getStock, delStock, addStock, updateStock, exportStock} from "@/api/operate/stock";
import {getResumeToBelongs} from "@/api/publish/resume";

export default {
  name: "FinishStock",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人才股票表格数据
      stockList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        name: null,
        openPrice: null,
        lastClosePrice: null,
        maxPrice: null,
        minPrice: null,
        latestPrice: null,
        volume: null,
        turnover: null,
        amount: null,
        deptId: null,
        createById: null,
        updateById: null,
      },
      // 表单参数
      form: {},
      // 发行人信息
      issuer: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询人才股票列表 */
    getList() {
      this.loading = true;
      listOngoStock(this.queryParams).then(response => {
        this.stockList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        name: null,
        openPrice: null,
        lastClosePrice: null,
        maxPrice: null,
        minPrice: null,
        latestPrice: null,
        volume: null,
        turnover: null,
        amount: null,
        deptId: null,
        createBy: null,
        createById: null,
        createTime: null,
        updateBy: null,
        updateById: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getStock(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "人才股票";
        const _this = this;
        // 查询发行人简历
        getResumeToBelongs(this.form.owner).then(async response => {
          if (response && response.code === 200) {
            _this.issuer = response.data;
          }
        })
      });
    },
  }
};
</script>
<style scoped>
.margin-top {
  margin-top: 20px;
}
</style>
